package com.example.wordapp.controller;


import com.example.wordapp.pojo.Comments;
import com.example.wordapp.pojo.Result;
import com.example.wordapp.service.CommentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    @RequestMapping("/list")
    public Result list(HttpServletRequest request) {
        log.info("查询所有留言列表");
        List<Comments> all = commentsService.findAll();
        return Result.success(all);
    }

    @RequestMapping("/add")
    public Result add(HttpServletRequest request, @RequestBody Comments comments) {
        log.info("添加留言 {}", comments);
        int updateRow = commentsService.addComment(comments);
        return Result.success();
    }
}
